<?php

 /**
  * @package JooS
  * @subpackage Syntax_PHPackager
  */

  require_once "JooS/Syntax/Complex/Transition.php";

  class JooS_Syntax_PHPackager_Config_Syntax extends JooS_Syntax_Complex_Transition {
    /**
     * @return string
     */
    public function compile() {
      $ret = parent::compile();
      if ($ret !== false) {
        require_once "JooS/Namespace.php";

        $configPath = $this->getParsedValue(1);
        if ($configPath === "")
          return false;

        $names = explode(JooS_Namespace::DELIMITER, $configPath);
        $configInstance = array_shift($names);
        $configPath = implode("->", $names);

        if ($configPath === "")
          return false;
        
        $ret = "\$this->getConfig('" . $configInstance . "')->" . $configPath;
      }
      return $ret;
    }

    /**
     * @return JooS_Syntax_Complex_Concatenate
     */
    protected function createRule() {
      return $this->createSyntax("Complex_Concatenate", array(
        $this->createSyntax("Simple_Symbol", "#"), 
        $this->createSyntax("PHPackager_Variable_Path")
      ));
    }
  }
